package auth.service;

import auth.component.RedisConstant;
import cn.hutool.core.collection.CollUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@Service
public class ResourceServiceImpl {

    private Map<String, List<String>> resourceRolesMap;

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @PostConstruct
    public void initData() {
        resourceRolesMap = new TreeMap<>();
        resourceRolesMap.put("/user/userList", CollUtil.toList("ADMIN"));
        resourceRolesMap.put("/user/modUser", CollUtil.toList("ADMIN","ACCOUNT","CARRIER","DRIVER"));
        resourceRolesMap.put("/user/delUser", CollUtil.toList("ADMIN","ACCOUNT","CARRIER","DRIVER"));

        resourceRolesMap.put("/carrier/getCarrier", CollUtil.toList("ADMIN","ACCOUNT","CARRIER","DRIVER"));
        resourceRolesMap.put("/carrier/carrierList", CollUtil.toList("ADMIN","ACCOUNT","CARRIER","DRIVER"));
        resourceRolesMap.put("/carrier/modCarrier", CollUtil.toList("ADMIN","CARRIER"));
        resourceRolesMap.put("/carrier/driverList", CollUtil.toList("ADMIN","CARRIER"));
        resourceRolesMap.put("/carrier/truckList", CollUtil.toList("ADMIN","CARRIER"));
        resourceRolesMap.put("/carrier/addDriver", CollUtil.toList("ADMIN","CARRIER"));
        resourceRolesMap.put("/carrier/addTruck", CollUtil.toList("ADMIN","CARRIER"));

        resourceRolesMap.put("/order/shippingOrderList", CollUtil.toList("ADMIN","ACCOUNT","CARRIER"));
        resourceRolesMap.put("/order/createShippingOrder", CollUtil.toList("ADMIN","ACCOUNT"));
        resourceRolesMap.put("/order/delShippingOrder", CollUtil.toList("ADMIN","ACCOUNT"));
        resourceRolesMap.put("/order/accountOperate", CollUtil.toList("ADMIN","ACCOUNT"));
        resourceRolesMap.put("/order/takeOrder", CollUtil.toList("ADMIN","CARRIER"));
        resourceRolesMap.put("/order/createTruckOrder", CollUtil.toList("ADMIN","CARRIER"));
        resourceRolesMap.put("/order/getTruckOrder", CollUtil.toList("ADMIN","DRIVER"));
        resourceRolesMap.put("/order/driverOperate", CollUtil.toList("ADMIN","DRIVER"));

        redisTemplate.opsForHash().putAll(RedisConstant.RESOURCE_ROLES_MAP, resourceRolesMap);
    }
}
